﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PlanB.ShareDove.ConferenceOrganization.BusinessLayer.DataLayerInterface.Entities;
using System.Diagnostics;
using PlanB.Core.Configuration;
using PlanB.ShareDove.ConferenceOrganization.BusinessLayer;
using Microsoft.SharePoint;

namespace PlanB.ShareDove.ConferenceOrganization.Portal.WebParts.MVP
{
    /// <summary>
    /// DisplaySessions Webpart Presenter
    /// </summary>
    public class DisplaySessionsPresenter
    {
        #region member variables
        private IDisplaySessionsView m_View;

        #endregion


        #region constructors
        /// <summary>
        /// Construct the presenter for the DisplaySessions web part
        /// </summary>
        /// <param name="view">View used in the DisplaySessions web part</param>
        public DisplaySessionsPresenter(IDisplaySessionsView view)
        {
            this.m_View = view;
        }
        #endregion

        #region public methods
        /// <summary>
        /// Retreive Cities Data from SharePoint
        /// </summary>
        public void RetreiveSessionData()
        {
            try
            {
                List<ConferenceSession> allSessions = new List<ConferenceSession>();

                //
                //TODO: replace with values from Configuration List
                ConfigurationInformation configuration = new ConfigurationInformation()
                {
                    DataLayerImplementationAssembly = "PlanB.ShareDove.ConferenceOrganization.SharePointDataLayer, Version=0.0.0.1, Culture=neutral, PublicKeyToken=79ea5ba3438af0bf",
                    DataLayerImplementationClassName = "PlanB.ShareDove.ConferenceOrganization.DataLayer.SharePointDataLayer.SharePointDataLayer"
                };
                ConferenceOrganizationBusinessProcesses businessLayer = new ConferenceOrganizationBusinessProcesses(configuration);
                DateTime day = new DateTime(2011, 10, 19); // TODO: Initialize to an appropriate value
                IEnumerable<ConferenceSession> sessions;
                object context = SPContext.Current.Web;
                sessions = businessLayer.GetSessionsForDay(context, day);

                DisplaySessionsModel sessionsViewData = new DisplaySessionsModel();
                sessionsViewData.SessionData = sessions;
                m_View.SetData(sessionsViewData);
            }
            catch (Exception ex)
            {
                //TODO: Exception Handling
                Debug.Print(ex.Message);
            }
        }
        #endregion
    }
}
